home *** CD-ROM | disk | FTP | other *** search
/ Programming an RTS Game with Direct3D / Programming an RTS Game with Direct3D.iso / Examples / Chapter 14 / Example 14.1 / Debug / Shaders / fire.vs < prev    next >
Encoding:
Text File  |  2006-06-23  |  1.7 KB  |  57 lines

  1. //////////////////////////////////////////////////////////////////////////
  2. //                                                                      //
  3. //                        Fire Vertexshader                             //
  4. //                                                                      //
  5. //                   Written by C. Granberg, 2006                       //
  6. //                                                                      //
  7. //////////////////////////////////////////////////////////////////////////
  8.  
  9. uniform extern float4x4 matW;
  10. uniform extern float4x4 matVP;
  11. uniform extern float3 DirToCam;
  12. uniform extern float time;
  13. uniform extern float offset;
  14.  
  15. struct VS_INPUT
  16. {
  17.    float4 position : POSITION0;
  18.    float3 normal   : NORMAL0;
  19.    float2 UV       : TEXCOORD0;
  20. };
  21.  
  22. struct VS_OUTPUT
  23. {
  24.    float4 position  : POSITION0;
  25.    float2 UV        : TEXCOORD0;
  26.    float2 UV_Noise1 : TEXCOORD1;
  27.    float2 UV_Noise2 : TEXCOORD2;
  28.    float2 UV_Noise3 : TEXCOORD3;
  29.    float  mainAlpha : TEXCOORD4;
  30. };
  31.  
  32. VS_OUTPUT Main(VS_INPUT input)
  33. {
  34.    VS_OUTPUT output = (VS_OUTPUT)0;
  35.  
  36.    // Project position
  37.    float4 temp = mul(input.position, matW);
  38.    output.position = mul(temp, matVP);
  39.  
  40.    //copy main UV coordinates across 
  41.    output.UV = input.UV;
  42.  
  43.    //Generate noise coordinates as a function of time
  44.    output.UV_Noise1 = input.UV + float2(time * 0.7f + offset, time);
  45.    output.UV_Noise2 = input.UV + float2(-time * 0.11f, time * 0.93f + offset);
  46.    output.UV_Noise3 = input.UV + float2(time * 0.3f - offset, time * 0.71f);
  47.  
  48.    //Transform normal
  49.    input.normal = mul(input.normal, matW);
  50.  
  51.    //Calculate mainAlpha
  52.    output.mainAlpha = abs(dot(normalize(input.normal), DirToCam));
  53.  
  54.    return output;
  55. }
  56.  
  57.